code vault - copy_fileWhat links here?
This copies a file from one location to another, preserving the creation and last access times.

Code

//#############################################################################
void copy_file(char* source, char* destination)
{
    FILE*   infile;
    FILE*   outfile;
    char*   buffer[8192];
    size_t  count_read;
    size_t  count_written;
    
    if(infile = fopen(source, "rb")) {
        if (outfile = fopen(destination, "wb")) {
            while (!feof(infile) && !ferror(outfile)) {
                count_read = fread(buffer, 1, 8192, infile);
                count_written = fwrite(buffer, 1, count_read, outfile);
            }
            fclose(outfile);
            struct stat buf;
            stat(source, &buf);
            utimbuf times;
            times.actime  = buf.st_atime;
            times.modtime = buf.st_mtime;
            utime(destination, &times);
        }
        else {
            printf("failed to open %s for output\n", destination);
        }
        fclose(infile);
    }
    else {
        printf("failed to open %s for input\n", source);
    }
}


code vault - copy_file
filename:code vault - copy_file
filename:code%20vault%20%2D%20copy_file
last edit:March 26 2009 18:35:48 (5519 days ago)
ct = 1714989258.000000 = May 06 2024 05:54:18
ft = 1238106948.000000 = March 26 2009 18:35:48
dt = 476882310.000000